package com.ruoyi.web.controller.drugSystem.drugInfo;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.drugSystem.domain.SysStockRk;
import com.ruoyi.drugSystem.service.ISysStockRkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库清单Controller
 *
 * @author ruoyi
 * @date 2023-03-11
 */
@RestController
@RequestMapping("/system/rk")
public class SysStockRkController extends BaseController
{
    @Autowired
    private ISysStockRkService sysStockRkService;

    /**
     * 查询入库清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:rk:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStockRk sysStockRk)
    {
        startPage();
        List<SysStockRk> list = sysStockRkService.selectSysStockRkList(sysStockRk);
        return getDataTable(list);
    }

    /**
     * 导出入库清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:rk:export')")
    @Log(title = "入库清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysStockRk sysStockRk)
    {
        List<SysStockRk> list = sysStockRkService.selectSysStockRkList(sysStockRk);
        ExcelUtil<SysStockRk> util = new ExcelUtil<SysStockRk>(SysStockRk.class);
        util.exportExcel(response, list, "入库清单数据");
    }

    /**
     * 获取入库清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysStockRkService.selectSysStockRkById(id));
    }

    /**
     * 新增入库清单
     */
    @PreAuthorize("@ss.hasPermi('system:rk:add')")
    @Log(title = "入库清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStockRk sysStockRk)
    {
        return toAjax(sysStockRkService.insertSysStockRk(sysStockRk));
    }

    /**
     * 修改入库清单
     */
    @PreAuthorize("@ss.hasPermi('system:rk:edit')")
    @Log(title = "入库清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStockRk sysStockRk)
    {
        return toAjax(sysStockRkService.updateSysStockRk(sysStockRk));
    }

    /**
     * 删除入库清单
     */
    @PreAuthorize("@ss.hasPermi('system:rk:remove')")
    @Log(title = "入库清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysStockRkService.deleteSysStockRkByIds(ids));
    }
}